<template>
  <div class="fd-evaluation-pane">
    <!--TODO: 设置用户的习惯按钮 -->
    <el-tooltip class="item" content="自定义表格显示列" effect="dark" placement="top">
      <button class="set-fd-cell" @click="setDialogVisible = true"></button>
    </el-tooltip>
    <div class="custom-top">
      <div class="btn">
        <div class="left">
          <el-link icon="el-icon-folder-checked" @click="fdSaveAll">
            {{ $t('button.submitAfterApprove') }}
          </el-link>
          <el-link icon="el-icon-download" style="margin-left: 15px" @click="rowDown">
            {{ $t('FdData.exportExcel') }}
          </el-link>
          <el-link icon="el-icon-upload2" style="margin-left: 15px" @click="uploadFile">
            {{ $t('FdData.importExcel') }}
          </el-link>

          <input ref="inputfile" class="upload" type="file" @change="inputfileChange" />
        </div>
        <div class="right">
          <el-button
            v-show="claimMde"
            icon="el-icon-finished"
            size="mini"
            style="margin-right: 15px"
            type="success"
            @click="multClaimSubmission"
          >
            批量认领提交
          </el-button>
          <el-switch
            v-model="claimMde"
            active-color="#13ce66"
            active-text="批量认领"
            inactive-color="#409EFF"
            inactive-text="单行认领"
            style="display: inline-block;margin-right: 15px"
          ></el-switch>

          <el-radio-group v-model="dataType" size="mini">
            <el-radio-button label="all">{{ $t('button.all') }}</el-radio-button>
            <el-radio-button label="hasCost">{{ $t('FdData.hasCost') }}</el-radio-button>
            <el-radio-button label="unCost">{{ $t('FdData.unCost') }}</el-radio-button>
            <el-radio-button label="personalAll">我的估价</el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div class="total-result">
        <table>
          <tr>
            <td>总行数：{{ totalResult.totalLen }}</td>
            |
            <td>当前行数：{{ totalResult.currentLen }}</td>
            |
            <td>Base Price：{{ totalResult.basePrice }}</td>
            |
            <td>GCM Total Cost Delta：{{ totalResult.gcmTotalCostDelta }}</td>
          </tr>
        </table>
      </div>
    </div>
    <div v-loading="isRequesting" class="custom-bottom">
      <VirtualTable
        :cb="totalCb"
        cbArgs="basePrice,gcmTotalCostDelta"
        :filterable="true"
        :header-cell-style="$headerCellStyle"
        :rowStyle="rowStyle"
        rowKey="fdRowId"
        :table="tableListFilter"
      >
        <!-- rowNo -->
        <Cell fix="left" :label="$t('FdData.rowNo')" :width="50">
          <template slot-scope="scope">
            <span>{{ scope.index + 1 }}</span>
          </template>
        </Cell>
        <!-- basePartName -->
        <Cell
          v-if="cellIsShow.IsFixBasePartName"
          fix="left"
          :label="$t('FdData.basePartName')"
          prop="basePartName"
          sort
          :width="150"
        />
        <!-- basePartNo -->
        <Cell
          v-if="cellIsShow.IsFixBasePartNo"
          fix="left"
          :label="$t('FdData.basePartNo')"
          prop="basePartNo"
          sort
          :width="150"
        />
        <!-- newPartName -->
        <Cell
          v-if="cellIsShow.IsFixNewPartName"
          fix="left"
          :label="$t('FdData.newPartName')"
          prop="newPartName"
          sort
          :width="150"
        />
        <!-- newPartNo -->
        <Cell
          v-if="cellIsShow.IsFixNewPartNo"
          fix="left"
          :label="$t('FdData.newPartNo')"
          prop="newPartNo"
          sort
          :width="150"
        />
        <!-- rdFunction -->
        <Cell
          v-if="cellIsShow.IsRDFunction"
          :label="$t('FdData.rdFunction')"
          prop="rdFunction"
          sort
        />
        <!-- category -->
        <Cell v-if="cellIsShow.IsCategory" :label="$t('FdData.category')" prop="category" sort />
        <!-- itemNo -->
        <Cell v-if="cellIsShow.IsItemNo" :label="$t('FdData.itemNo')" prop="itemNo" sort="number" />
        <!-- rdOwner -->
        <Cell v-if="cellIsShow.IsRDOwner" :label="$t('FdData.rdOwner')" prop="rdOwner" sort />
        <!-- trackingOption -->
        <Cell
          v-if="cellIsShow.IsTrackingOption"
          :label="$t('FdData.trackingOption')"
          prop="trackingOption"
          sort
        />
        <!-- optionType -->
        <Cell v-if="cellIsShow.IsOptionType" :label="$t('FdData.optionType')" prop="optionType" />
        <!-- baseProject -->
        <Cell :label="$t('FdData.baseProject')">
          <!-- basePartName -->
          <Cell
            v-if="cellIsShow.IsBasePartName"
            :label="$t('FdData.basePartName')"
            prop="basePartName"
            sort
            :width="150"
          />
          <!-- basePartNo -->
          <Cell
            v-if="cellIsShow.IsBasePartNo"
            :label="$t('FdData.basePartNo')"
            prop="basePartNo"
            sort
            :width="150"
          />
          <!-- baseMaterialGroup -->
          <Cell
            v-if="cellIsShow.IsBaseMaterialGroup"
            :label="$t('FdData.MaterialGroup')"
            prop="baseMaterialGroup"
            sort
          />
          <!-- baseMaterialDetail -->
          <Cell
            v-if="cellIsShow.IsBaseMaterialDetail"
            :label="$t('FdData.MaterialDetail')"
            prop="baseMaterialDetail"
            sort
          />
          <!-- baseMaterialColor -->
          <Cell
            v-if="cellIsShow.IsBaseMaterialColor"
            :label="$t('FdData.baseMaterialColor')"
            prop="baseMaterialColor"
            sort
          />
          <!-- baseSize -->
          <Cell
            v-if="cellIsShow.IsBaseSize"
            :label="$t('FdData.baseSize')"
            prop="baseSize"
            sort="number"
          />
          <!-- baseQty -->
          <Cell
            v-if="cellIsShow.IsBaseQty"
            :label="$t('FdData.baseQty')"
            prop="baseQty"
            sort="number"
          />
          <!-- baseIdProcess -->
          <Cell
            v-if="cellIsShow.IsBaseIdProcess"
            :label="$t('FdData.baseIdProcess')"
            prop="baseIdProcess"
            sort
          />
          <!-- baseSupplier -->
          <Cell
            v-if="cellIsShow.IsBaseSupplier"
            :label="$t('FdData.baseSupplier')"
            prop="baseSupplier"
            sort
          />
          <!-- baseSupplierPn -->
          <Cell
            v-if="cellIsShow.IsBaseSupplierPn"
            :label="$t('FdData.baseSupplierPn')"
            prop="baseSupplierPn"
            sort
          />
          <!-- baseRemark -->
          <Cell v-if="cellIsShow.IsBaseRemark" :label="$t('FdData.baseRemark')" prop="baseRemark" />
          <!-- baseViewPic -->
          <Cell
            v-if="cellIsShow.IsBaseViewPic"
            :label="$t('FdData.baseViewPic')"
            prop="basePicture"
          >
            <template slot-scope="scope">
              <BaseViewBtn @click="fdPicList(scope.row, false)">
                {{ scope.row.basePicture }}
              </BaseViewBtn>
            </template>
          </Cell>
          <!-- baseSapStandardPrice -->
          <Cell
            v-if="cellIsShow.IsBaseSapStandardPrice"
            :label="$t('FdData.baseSapStandardPrice')"
            prop="baseSapStandardPrice"
            sort="number"
          />
          <!-- basePrice -->
          <Cell
            v-if="cellIsShow.IsBasePrice"
            :label="$t('FdData.basePrice')"
            prop="basePrice"
            sort="number"
          />
          <!-- baseTecCost -->
          <Cell
            v-if="cellIsShow.IsBaseTecCost"
            :label="$t('FdData.baseTecCost')"
            prop="baseTecCost"
            sort="number"
          />
        </Cell>
        <!-- newProject -->
        <Cell :label="$t('FdData.newProject')">
          <!-- newPartName -->
          <Cell
            v-if="cellIsShow.IsNewPartName"
            :label="$t('FdData.newPartName')"
            prop="newPartName"
            sort
            :width="150"
          />
          <!-- newPartNo -->
          <Cell
            v-if="cellIsShow.IsNewPartNo"
            :label="$t('FdData.newPartNo')"
            prop="newPartNo"
            sort
            :width="150"
          />
          <!-- commodity -->
          <Cell
            v-if="cellIsShow.IsNewCommodity"
            :label="$t('FdData.commodity')"
            prop="commodity"
            sort
          />
          <!-- newTempPartNo -->
          <Cell
            v-if="cellIsShow.IsNewTempPartNo"
            :label="$t('FdData.newTempPartNo')"
            prop="newTempPartNo"
            sort
          />
          <!-- newMaterialGroup -->
          <Cell
            v-if="cellIsShow.IsNewMaterialGroup"
            :label="$t('FdData.MaterialGroup')"
            prop="newMaterialGroup"
            sort
          />
          <!-- newMaterialDetail -->
          <Cell
            v-if="cellIsShow.IsNewMaterialDetail"
            :label="$t('FdData.MaterialDetail')"
            prop="newMaterialDetail"
            sort
          />
          <!-- newMaterialColor -->
          <Cell
            v-if="cellIsShow.IsNewMaterialColor"
            :label="$t('FdData.newMaterialColor')"
            prop="newMaterialColor"
            sort
          />
          <!-- newSize -->
          <Cell
            v-if="cellIsShow.IsNewSize"
            :label="$t('FdData.newSize')"
            prop="newSize"
            sort="number"
          />
          <!-- newQty -->
          <Cell
            v-if="cellIsShow.IsNewQty"
            :label="$t('FdData.newQty')"
            prop="newQty"
            sort="number"
          />
          <!-- newIdProcess -->
          <Cell
            v-if="cellIsShow.IsNewIdProcess"
            :label="$t('FdData.newIdProcess')"
            prop="newIdProcess"
            sort
          />
          <!-- newSupplier -->
          <Cell
            v-if="cellIsShow.IsNewSupplier"
            :label="$t('FdData.newSupplier')"
            prop="newSupplier"
            sort
          />
          <!-- newSupplierPn -->
          <Cell
            v-if="cellIsShow.IsNewSupplierPn"
            :label="$t('FdData.newSupplierPn')"
            prop="newSupplierPn"
            sort
          />
          <!-- newTooling -->
          <Cell
            v-if="cellIsShow.IsNewTooling"
            :label="$t('FdData.newTooling')"
            prop="newTooling"
            sort
          >
            <template slot-scope="scope">
              <span>{{ scope.row.newTooling ? 'Y' : 'N' }}</span>
            </template>
          </Cell>
          <!-- newRemark -->
          <Cell v-if="cellIsShow.IsNewRemark" :label="$t('FdData.newRemark')" prop="newRemark" />
          <!-- newViewPic -->
          <Cell v-if="cellIsShow.IsNewViewPic" :label="$t('FdData.newViewPic')" prop="newPicture">
            <template slot-scope="scope">
              <BaseViewBtn @click="fdPicList(scope.row, true)">
                {{ scope.row.newPicture }}
              </BaseViewBtn>
            </template>
          </Cell>
          <!-- newSapStandardPrice -->
          <Cell
            v-if="cellIsShow.IsNewSapStandardPrice"
            :label="$t('FdData.newSapStandardPrice')"
            prop="newSapStandardPrice"
            sort="number"
          />
          <!-- newPrice -->
          <Cell
            v-if="cellIsShow.IsNewPrice"
            :label="$t('FdData.newPrice')"
            prop="newPrice"
            sort="number"
          />
          <!-- newTecCost -->
          <Cell
            v-if="cellIsShow.IsNewTecCost"
            :label="$t('FdData.newTecCost')"
            prop="newTecCost"
            sort="number"
          />
        </Cell>
        <!-- statusCompare -->
        <Cell
          v-if="cellIsShow.IsStatusCompare"
          :label="$t('FdData.statusCompare')"
          prop="statusCompare"
          sort="number"
        />
        <!-- gapType -->
        <Cell
          v-if="cellIsShow.IsGapType"
          :label="$t('FdData.gapType')"
          prop="gapType"
          sort="number"
        />
        <!-- gapReason -->
        <Cell v-if="cellIsShow.IsGapReason" :label="$t('FdData.gapReason')" prop="gapReason" />
        <!-- gcm -->
        <Cell :label="$t('FdData.gcm')">
          <!-- gcmFunction -->
          <Cell
            v-if="cellIsShow.IsGcmFunction"
            :label="$t('FdData.gcmFunction')"
            prop="gcmFunction"
            sort
          />
          <!-- GcmOwner -->
          <Cell v-if="cellIsShow.IsGcmOwner" :label="$t('FdData.gcmOwner')" prop="gcmOwner">
            <template slot-scope="scope">
              {{ gcmOwnerById(scope.row.gcmOwner) }}
            </template>
          </Cell>
          <!-- gcmCost -->
          <!-- <Cell
            v-if="cellIsShow.IsGcmCost"
            :label="$t('FdData.gcmCost')"
            prop="gcmCost"
            sort="number"
          /> -->
          <!-- gcmCostDelta -->
          <Cell
            v-if="cellIsShow.IsGcmTotalCostDelta"
            :label="$t('FdData.gcmTotalCostDelta')"
            prop="gcmTotalCostDelta"
            sort="number"
          />
          <!-- gcmCostRemark -->
          <Cell
            v-if="cellIsShow.IsGcmCostRemark"
            :label="$t('FdData.gcmCostRemark')"
            prop="gcmCostRemark"
          />
        </Cell>
        <!-- pirDelta -->
        <!-- <Cell
          v-if="cellIsShow.IsPirDelta"
          :label="$t('FdData.pirDelta')"
          prop="pirDelta"
          sort="number"
        /> -->
        <!-- 估价提交状态 -->
        <Cell fix="right" label="估价提交状态" :width="100">
          <template slot-scope="scope">
            <span :class="scope.row.isGcmCommit ? 'tag-blue' : 'tag-red'">
              {{ scope.row.isGcmCommit ? '已提交' : '未提交' }}
            </span>
          </template>
        </Cell>
        <!-- 估价状态 -->
        <Cell fix="right" label="估价状态" :width="100">
          <template slot-scope="scope">
            <span :class="scope.row.isGcmCost ? 'tag-blue' : 'tag-red'">
              {{ scope.row.isGcmCost ? '已估价' : '未估价' }}
            </span>
          </template>
        </Cell>

        <!-- 驳回状态 -->
        <Cell fix="right" label="驳回状态" :width="100">
          <template slot-scope="scope">
            <span :class="scope.row.isGcmReject ? 'tag-blue' : 'tag-red'">
              {{ scope.row.isGcmReject ? '已驳回' : '未驳回' }}
            </span>
          </template>
        </Cell>
        <!-- 认领状态 -->
        <Cell fix="right" label="认领状态" :width="100">
          <template slot-scope="scope">
            <span :class="scope.row.isGcmClaim === false ? 'tag-red' : 'tag-blue'">
              {{ scope.row.isGcmClaim === false ? '未认领' : '已认领' }}
            </span>
          </template>
        </Cell>

        <!-- 操作 -->
        <Cell fix="right" label="操作" :width="140">
          <template slot-scope="scope">
            <el-dropdown size="mini" split-button trigger="click">
              <!-- 编辑 -->
              <el-link
                :disabled="
                  scope.row.isGcmReject ||
                    scope.row.isGcmClaim === false ||
                    !isSessionUserRowData(scope.row)
                "
                icon="el-icon-edit-outline"
                :underline="false"
                @click="rowEvaluation(scope.index, scope.row)"
              >
                {{ $t('button.edit') }}
              </el-link>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>
                  <!-- 认领 -->
                  <el-link
                    :disabled="scope.row.isGcmClaim !== false || !isSessionUserRowData(scope.row)"
                    icon="el-icon-document-add"
                    :underline="false"
                    @click="claimTask(scope.row)"
                  >
                    {{ $t('button.claim') }}
                  </el-link>
                </el-dropdown-item>
                <el-dropdown-item>
                  <!-- 转发 -->
                  <el-link
                    :disabled="
                      scope.row.isGcmCost ||
                        scope.row.isGcmReject ||
                        scope.row.isGcmClaim === false ||
                        !isSessionUserRowData(scope.row)
                    "
                    icon="el-icon-share"
                    :underline="false"
                    @click="rowForward(scope.index, scope.row)"
                  >
                    {{ $t('button.forward') }}
                  </el-link>
                </el-dropdown-item>
                <el-dropdown-item>
                  <!-- 驳回 -->
                  <el-link
                    :disabled="
                      scope.row.isGcmCost ||
                        scope.row.isGcmReject ||
                        scope.row.isGcmClaim === false ||
                        !isSessionUserRowData(scope.row)
                    "
                    icon="el-icon-s-release"
                    :underline="false"
                    @click="rowReject(scope.index, scope.row)"
                  >
                    {{ $t('button.reject') }}
                  </el-link>
                </el-dropdown-item>

                <el-dropdown-item>
                  <!-- 模型计算 -->
                  <el-link
                    icon="el-icon-mobile-phone"
                    :underline="false"
                    @click="rowModelCalc(scope.row)"
                  >
                    {{ $t('button.modelCalc') }}
                  </el-link>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            <!-- 批量认领复选框 -->
            <el-checkbox
              v-if="
                isSessionUserRowData(scope.row) &&
                  unClaimData.length &&
                  scope.row.isGcmClaim === false
              "
              v-model="scope.row.isSelect"
              @change="selectRow(scope.row, $event)"
            ></el-checkbox>
          </template>
        </Cell>
      </VirtualTable>
    </div>

    <!-- 估价对话框 -->
    <BaseDialog
      v-if="evaluationDialogVisible"
      :title="$t('button.edit')"
      :visible.sync="evaluationDialogVisible"
      width="600px"
    >
      <FdEvaluationEdit
        :current-row-no="currentRowNo"
        :input-data="currentEditRow"
        @cancel="evaluationDialogVisible = false"
        @save="afterEvaluationSave"
      />
    </BaseDialog>

    <!-- 转发对话框 -->
    <BaseDialog
      v-if="forwardDialogVisible"
      :title="$t('button.forward')"
      :visible.sync="forwardDialogVisible"
      width="600px"
    >
      <FdEvaluationEditForward
        :current-row-no="currentRowNo"
        :input-data="currentEditRow"
        :task-data="taskData"
        @cancel="forwardDialogVisible = false"
        @save="afterEvaluationForwardSave"
      />
    </BaseDialog>
    <!-- 驳回对话框 -->
    <BaseDialog
      v-if="rejectDialogVisible"
      :title="$t('button.reject')"
      :visible.sync="rejectDialogVisible"
      width="500px"
    >
      <FdEvaluationEditReject
        :input-data="currentEditRow"
        :task-data="taskData"
        @cancel="rejectDialogVisible = false"
        @save="afterEvaluationRejectSave"
      />
    </BaseDialog>

    <!--图片对话框-->
    <BaseDialog
      v-if="picDialogVisible"
      :title="$t('FdData.viewPic')"
      :visible.sync="picDialogVisible"
      width="400px"
    >
      <BaseIdpPicView
        :idp-token="idpToken"
        :pic-list="picList"
        @cancel="picDialogVisible = false"
      />
    </BaseDialog>

    <!--模型计算框-->
    <BaseDialog
      v-if="modelCalcVisible"
      :title="$t('FdData.modelCalc')"
      :visible.sync="modelCalcVisible"
      width="1000px"
    >
      <CalcModel
        :commodity="currentEditRow.commodity"
        :fdRowId="currentEditRow.fdRowId"
        :gcmFunction="currentEditRow.gcmFunction"
        @cancel="modelCalcVisible = false"
      />
    </BaseDialog>

    <!--TODO: 设置显示列对话框 -->
    <BaseDialog
      v-if="setDialogVisible"
      title="设置显示列"
      :visible.sync="setDialogVisible"
      width="50%"
    >
      <FdCellShowSet
        :cellIsShow="cellIsShow"
        :pageId="pageId"
        @cancel="setDialogVisible = false"
        @saveOperationData="saveOperationData"
      />
    </BaseDialog>
  </div>
</template>
<script>
import FdEvaluationEdit from './FdEvaluationEdit'
import FdEvaluationEditForward from './FdEvaluationEditForward'
import FdEvaluationEditReject from './FdEvaluationEditReject'
import { fdCostCommit, fdCostSaveBatch, fdCostTaskClaim, fdClaimBatch } from '@/api/quote/cost'
import { idpGetToken } from '@/api/quote/idp'
import { fdRowPictureList } from '@/api/quote/fd-row-picture'
import { fileExportCostTask } from '@/api/quote/file-export'
import XLSX from 'xlsx'
import CalcModel from '@/components/model/calc/components/CalcModel.vue'
import Cell from '@/widgets/VirtualTable/Cell'
import VirtualTable from '@/widgets/VirtualTable/Table'
import fdCell from '@/mixins/fdCell'
import FdCellShowSet from '../../components/FdCellShowSet'
export default {
  name: 'FdEvaluationPane',
  components: {
    FdEvaluationEdit,
    FdEvaluationEditForward,
    CalcModel,
    Cell,
    VirtualTable,
    FdCellShowSet,
    FdEvaluationEditReject
  },
  mixins: [fdCell],

  props: {
    inputData: {
      default: () => null,
      type: Object
    },
    taskData: {
      default: () => null,
      type: Object
    },
    shareDataList: {
      default: () => [],
      type: Array
    }
  },
  data() {
    return {
      isRequesting: false,
      // 分配对话框可见标识
      evaluationDialogVisible: false,
      // 转发对话框可见标识
      forwardDialogVisible: false,
      // 驳回对话框
      rejectDialogVisible: false,
      // 认领确认框
      claimDialogVisible: false,
      // 当前修改行
      currentEditRow: {},
      // 当前行号
      currentRowNo: 0,
      // idp token
      idpToken: '',
      // 每一行的图片数据
      picList: [],
      // 图片对话框可见标识
      picDialogVisible: false,
      // 模型计算弹窗
      modelCalcVisible: false,
      // 是否估价的三种状态
      dataType: 'unCost',
      // 合计信息
      totalResult: {
        totalLen: 0,
        currentLen: 0,
        basePrice: 0,
        gcmCost: 0,
        gcmCostDelta: 0
      },
      // 正在刷新数组
      refreshPriceList: [],
      // 参考价格显示标识
      fdReferencePriceVisible: false,
      // 未进行估价的数据
      unDoneCostList: [],
      // 认领模式 false为单行认领 true为批量认领
      claimMde: false,
      // 选中的未认领数据
      selectedUnClaimData: [],
      setDialogVisible: false,
      pageId: 'FdEvaluationPane',
      cellIsShow: {}
    }
  },
  computed: {
    // 判断当前行是否属于该用户的未认领数据
    isSessionUserRowData() {
      return rowData => {
        const sessionUser = this.$store.getters['user/getSessionUser']
        if (!rowData.gcmOwner || !rowData.gcmOwner.length) return false
        const result = rowData.gcmOwner.findIndex(gcmOwner => {
          return gcmOwner.toLowerCase() === sessionUser.userId.toLowerCase()
        })
        return result !== -1
      }
    },
    // 所有未认领数据
    unClaimData() {
      let data = []
      if (!this.claimMde) {
        data = []
      } else {
        const sessionUser = this.$store.getters['user/getSessionUser']
        data = this.shareDataList.filter(item => {
          if (!item.gcmOwner || !item.gcmOwner.length) return false
          const result = item.gcmOwner.findIndex(gcmOwner => {
            return gcmOwner.toLowerCase() === sessionUser.userId.toLowerCase()
          })
          return result !== -1 && item.isGcmClaim === false
        })
      }
      return data
    },
    // 数据过滤
    tableListFilter() {
      const sessionUser = this.$store.getters['user/getSessionUser']
      if (this.dataType === 'all') {
        return this.shareDataList
      } else {
        return this.shareDataList.filter(item => {
          if (!item.gcmOwner || !item.gcmOwner.length) return false
          const result = item.gcmOwner.findIndex(gcmOwner => {
            return gcmOwner.toLowerCase() === sessionUser.userId.toLowerCase()
          })
          if (this.dataType === 'hasCost') {
            return result !== -1 && item.isGcmCost
          } else if (this.dataType === 'unCost') {
            return result !== -1 && !item.isGcmCost
          } else if (this.dataType === 'personalAll') {
            return result !== -1
          }
        })
      }
    }
  },

  mounted() {
    this.pageDataInit()
  },
  methods: {
    rowStyle(index, row) {
      if (this.unDoneCostList.find(item => item.fdRowId === row.fdRowId)) {
        return {
          backgroundColor: '#ffdada'
        }
      }
      if (this.unClaimData.length && this.unClaimData.find(item => item.fdRowId === row.fdRowId)) {
        return {
          backgroundColor: '#cccccc'
        }
      }
      return {
        backgroundColor: '#ffffff'
      }
    },

    // 下载
    async rowDown() {
      try {
        const sessionUser = this.$store.getters['user/getSessionUser']
        await this.$confirmBox(this.$t('button.down'), 'success')
        this.isRequesting = true
        const res = await fileExportCostTask(
          {
            taskId: this.inputData.taskId,
            userId: sessionUser.userId
          },
          { downExcelFile: true, msgSuccess: true, msgError: true }
        )
        this.$downFile(res)
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    // 上传数据
    uploadFile() {
      this.$refs['inputfile'].click()
    },
    // 读取文件
    inputfileChange(event) {
      const files = event.target.files

      if (!files) return

      const f = files[0]

      const reader = new FileReader()

      reader.onload = async e => {
        const data = e.target.result

        const workbook = XLSX.read(data, { type: 'array' })

        let sheet = workbook.Sheets[workbook.SheetNames[1]]

        // !ref 默认是表格第一行到最后一行(数据的最后一行)

        const maxColumn = sheet['!ref'].split(':')[1]

        sheet['!ref'] = `A2:${maxColumn}`

        // 行是合并单元格需重置

        const A2 = { w: '', t: 's' }
        const B2 = { w: '', t: 's' }
        const C2 = { w: '', t: 's' }
        const D2 = { w: '', t: 's' }
        const E2 = { w: '', t: 's' }
        const F2 = { w: '', t: 's' }
        const G2 = { w: '', t: 's' }

        const AM2 = { w: '', t: 's' }
        const AN2 = { w: '', t: 's' }
        const AO2 = { w: '', t: 's' }

        sheet = { ...sheet, A2, B2, C2, D2, E2, F2, G2, AM2, AN2, AO2 }

        sheet['D2'].w = 'fdRowId'
        sheet['AR2'].w = 'gcmTotalCostDelta'
        sheet['AS2'].w = 'gcmCostRemark'
        const result = XLSX.utils.sheet_to_json(sheet)

        this.saveUploadList(
          result.map(item => {
            return {
              fdRowId: item.fdRowId,
              gcmTotalCostDelta: item.gcmTotalCostDelta,
              gcmCostRemark: item.gcmCostRemark
            }
          })
        )

        event.target.value = ''
        this.dataType = 'hasCost'
      }
      reader.readAsArrayBuffer(f)
    },

    // save
    async saveUploadList(list) {
      try {
        this.isRequesting = true

        const uploadList = list.filter(item => String(item.gcmTotalCostDelta).trim() !== '')
        await fdCostSaveBatch(uploadList, { msgSuccess: true, msgError: true })

        this.$emit('update')
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },

    // 查看fd每一行图片列表
    async fdPicList(data, isNew) {
      const res = await fdRowPictureList({ fdRowId: data.fdRowId, isNew: isNew })
      this.picList = res.data
      this.picDialogVisible = true
    },

    async getIdpGetToken() {
      try {
        const idpTokenRes = await idpGetToken({})
        this.idpToken = idpTokenRes.data.accessToken
      } catch (error) {
        console.log(error)
      }
    },

    pageDataInit() {
      this.getIdpGetToken()
    },
    /* 行记录估价*/
    rowEvaluation(index, row) {
      this.currentRowNo = index + 1
      this.currentEditRow = JSON.parse(JSON.stringify(row))
      this.evaluationDialogVisible = true
    },

    /* 行记录转发*/
    rowForward(index, row) {
      this.currentRowNo = index + 1
      this.currentEditRow = JSON.parse(JSON.stringify(row))
      this.forwardDialogVisible = true
    },
    /* 行记录驳回*/
    rowReject(index, row) {
      this.currentEditRow = JSON.parse(JSON.stringify(row))
      this.rejectDialogVisible = true
    },

    /* 行记录认领 */
    async claimTask(rowData) {
      try {
        await this.$confirmBox(this.$t('button.claim'), 'warning')

        this.isRequesting = true
        await fdCostTaskClaim(
          {
            fdRowId: rowData.fdRowId
          },
          { msgSuccess: true, msgError: true }
        )
        this.$emit('update')
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    afterEvaluationSave() {
      this.evaluationDialogVisible = false
      this.$emit('update')
    },
    afterEvaluationForwardSave(data) {
      this.forwardDialogVisible = false
      this.$emit('update')
    },
    afterEvaluationRejectSave() {
      this.rejectDialogVisible = false
      this.$emit('update')
    },

    // 保存全部匹配结果
    async fdSaveAll() {
      try {
        await this.$confirmBox(this.$t('button.submit'), 'success')

        const sessionUser = this.$store.getters['user/getSessionUser']

        this.unDoneCostList = this.shareDataList.filter(item => {
          if (!item.gcmOwner || !item.gcmOwner.length) return false
          const result = item.gcmOwner.findIndex(gcmOwner => {
            return gcmOwner.toLowerCase() === sessionUser.userId.toLowerCase()
          })
          return result !== -1 && !item.isGcmCost
        })

        if (this.unDoneCostList.length > 0) {
          return this.$message({
            message: '存在未估价数据',
            type: 'error',
            duration: 1500
          })
        }

        const costPriceList = this.shareDataList
          .filter(item => {
            if (!item.gcmOwner || !item.gcmOwner.length) return false
            const result = item.gcmOwner.findIndex(gcmOwner => {
              return gcmOwner.toLowerCase() === sessionUser.userId.toLowerCase()
            })
            return result !== -1 && item.isGcmCost
          })
          .map(item => {
            return {
              commodity: item.commodity,
              fdRowId: item.fdRowId,
              gcmTotalCostDelta: item.gcmTotalCostDelta,
              gcmCostRemark: item.gcmCostRemark,
              isGcmCost: item.isGcmCost
            }
          })

        this.isRequesting = true

        await fdCostCommit(
          {
            fdId: this.taskData.fdId,
            version: this.taskData.version,
            taskId: this.taskData.taskId,
            costPriceList
          },
          { msgSuccess: true, msgError: true }
        )
        this.$emit('cancel')
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },

    rowModelCalc(row) {
      this.currentEditRow = row
      this.modelCalcVisible = true
    },

    totalCb(args) {
      this.totalResult = { ...args }
    },
    // 多行认领选中
    selectRow(rowData) {
      if (rowData.isSelect) {
        const index = this.selectedUnClaimData.findIndex(item => item.fdRowId === rowData.fdRowId)
        index === -1 && this.selectedUnClaimData.push(rowData)
      } else {
        const removeIndex = this.selectedUnClaimData.findIndex(
          item => item.fdRowId === rowData.fdRowId
        )
        removeIndex !== -1 && this.selectedUnClaimData.splice(removeIndex, 1)
      }
    },

    // 批量认领提交
    async multClaimSubmission() {
      try {
        await this.$confirmBox(this.$t('button.submit'), 'success')
        if (this.selectedUnClaimData.length <= 0) {
          return this.$message({
            message: '未选中任何数据',
            type: 'error',
            duration: 1500
          })
        }
        const selectedRow = this.selectedUnClaimData
          .filter(item => item.isSelect)
          .map(item => {
            return {
              fdRowId: item.fdRowId
            }
          })
        this.isRequesting = true
        await fdClaimBatch(selectedRow, { msgSuccess: true, msgError: true })
        this.$emit('update')

        // 清空选中行
        this.selectedUnClaimData = []
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.fd-evaluation-pane {
  .custom-top {
    width: calc(100% - 17px);
    height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;

    .btn {
      margin-top: 15px;
      width: 100%;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
  }

  /deep/ .custom-bottom {
    position: absolute;
    top: 80px;
    bottom: 0;
    left: 20px;
    right: 25px;
    .el-checkbox {
      font-size: 12px !important;
      margin-left: 10px;
    }

    .el-dropdown {
      font-size: unset;

      .el-button-group {
        height: 24px;
      }
      .el-button--mini {
        height: 24px;
        border: none !important;
        padding: 6px 5px !important;
      }
    }
  }
  .upload {
    width: 0;
    display: none;
  }
}

.el-dropdown-menu__item {
  /deep/ .el-link {
    justify-content: unset !important;
    width: 100% !important;
  }
}
</style>
